package com.netease.nim.demo.base;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

import com.netease.nim.demo.NimCache;
import com.netease.nim.demo.config.preference.Preferences;
import com.netease.nim.demo.contact.cache.ContactDataCache;
import com.netease.nim.demo.contact.cache.TeamDataCache;
import com.netease.nim.demo.contact.cache.TeamMemberInfoCache;
import com.netease.nim.demo.contact.protocol.ContactHttpClient;
import com.netease.nim.demo.database.DatabaseManager;
import com.netease.nim.demo.session.model.MsgListItem;
import com.netease.nim.demo.util.LogUtil;
import com.netease.nimlib.sdk.NIMClient;
import com.netease.nimlib.sdk.auth.AuthService;
import com.shwread.android.ui.dialog.SingleSignOnDialog;

import java.util.ArrayList;
import java.util.List;

import logic.constants.DefaultConsts;
import logic.util.AppUtils;
import logic.util.Util;


public class YXBaseActivity extends FragmentActivity {
    public static List<Activity> activityList = new ArrayList<>();
    public static List<MsgListItem> items = new ArrayList<>();


    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        activityList.add(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    public static void exit() {
        for (Activity activity : activityList) {
            LogUtil.e(DefaultConsts.TAG, "YXBaseActivity -->" + activity.getClass().getSimpleName() + " -- finish!!");
            activity.finish();
        }
        activityList.clear();
    }

    private static void onLogout() {
        TeamMemberInfoCache.destroy();
        TeamDataCache.getInstance().clearAll();
        ContactDataCache.getInstance().clearAll();
        NimCache.clear();
        NIMClient.getService(AuthService.class).logout();
        Preferences.saveUserToken("");
        DatabaseManager.getInstance().close();
        ContactDataCache.getInstance().clearBuddyCache();
        TeamDataCache.getInstance().clearTeamCache();
        ContactHttpClient.getInstance().resetToken();
    }

    @Override
    protected void onActivityResult(int arg0, int arg1, Intent arg2) {
        super.onActivityResult(arg0, arg1, arg2);
    }
}
